package com.asura.framework.rulemodel;

import java.util.List;

/**
 * 规则模型辅助工具类.
 * 
 * @author a123
 *
 */
public final class RuleModelHelper 
{

	/**
	 * 校验规则名称是否符合规范.
	 * 
	 * @param ruleNames
	 * @return
	 */
	public static boolean unlawfulRuleName( String... ruleNames )
	{
		if ( ruleNames == null )
		{
			return true;
		}

		for ( String ruleName : ruleNames )
		{
			if ( ruleName == null )
			{
				return true;
			}

			boolean unlawful = ruleName.startsWith( ConstantTable.getRuleNamePrefix( ), 0 );
			if ( !unlawful )
			{
				return true;
			}
		}

		return false;
	}

	/**
	 * 校验规则组是否符合规范.
	 * 
	 * @param groups
	 * @return
	 */
	public static boolean unlawfulRuleGroup( String... groups )
	{
		if ( groups == null )
		{
			return true;
		}

		for ( String group : groups )
		{
			if ( group == null )
			{
				return true;
			}
			boolean unlawful = group.startsWith( ConstantTable.getRuleGroupPrefix( ), 0 );
			if ( !unlawful )
			{
				return true;
			}
		}
		return false;
	}

	/**
	 * 
	 * @param nodes
	 * @return
	 */
	public static String[ ] assemblyRuleNames( List< TreeNode > nodes )
	{
		String[ ] ruleNames = new String[ nodes.size( ) ];
		for ( int index = 0, length = nodes.size( ); index < length; index++ )
		{
			ruleNames[ index ] = nodes.get( index ).getName( );
		}
		return ruleNames;
	}

	private RuleModelHelper( )
	{
		throw new AssertionError( "Uninstantiable class." );
	}
}
